package com.ldzy.Configurer;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @BelongsProject: spring-boot-demo
 * @BelongsPackage: com.ldzy.springbootdemo.config
 * @Author: wulangqi
 * @CreateTime: 2022-06-03  20:21
 * @Description: 拦截器配置，放行资源配置
 * @Version: 1.0
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    /**
     * @头像图片路径
     */
    @Value("${file.portraitImage.resource-path}")
    private String portraitImageResourcePath;
    @Value("${file.portraitImage.upload-path}")
    private String portraitImageUploadPath;

    /**
     * @首页资讯图片路径
     */
    @Value("${file.commodityImage.resource-path}")
    private String commodityImageResourcePath; // 首页资讯图片,映射路径
    @Value("${file.commodityImage.upload-path}")
    private String commodityImageUploadPath; // 首页资讯图片,上传路径


    /**
     * @author ：Lq
     * @date ：2022/10/22 13:55
     * @description ：静态资源放行
     */
    @Override

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/css/**").addResourceLocations("/css/");
        registry.addResourceHandler("/js/**").addResourceLocations("/js/");
        registry.addResourceHandler("/img/**").addResourceLocations("/img/");
        registry.addResourceHandler("/" + portraitImageResourcePath + "**").addResourceLocations("file:" + portraitImageUploadPath);// 服务器中存放图片的路径
        registry.addResourceHandler("/" + commodityImageResourcePath + "**").addResourceLocations("file:" + commodityImageUploadPath);// 服务器中存放图片的路径
      }

    /**
     * @author ：Lq
     * @date ：2022/10/22 13:54
     * @description ：设置拦截哪些路径，不拦截哪些路径
     */
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(myInterceptor())
//                // 拦截规则 ，拦截那些路径
//                .addPathPatterns("/**");
        // 添加白名单路径
//                .excludePathPatterns("/images/**", "/login", "/reg", "/reg/**","/product");
//                .excludePathPatterns("/user/api/login","/user/api/register");
    }

    /**
     * @author ：Lq
     * @date ：2022/10/22 13:55
     * @description ：全局注入拦截器并配置Bean
     * @return
     */
//    @Bean
//    public HandlerInterceptor myInterceptor() {
////        return new AuthenticationInterceptor();
//        return null;
//    }
//}

